package com.shanyi.sendmsg.tool;

import com.baidubce.http.ApiExplorerClient;
import com.baidubce.http.AppSigner;
import com.baidubce.http.HttpMethodName;
import com.baidubce.model.ApiExplorerRequest;
import com.baidubce.model.ApiExplorerResponse;
import com.shanyi.sendmsg.dto.req.WeatherQueryReqDto;
import org.springframework.stereotype.Service;

@Service
public class BaiduWeather {
    private static final String PATH = "http://gwgp-h4bqkmub7dg.n.bdcloudapi.com/day";
    private static final String AK = "18364e4d228d4ef58d8add6c90f94074";
    private static final String SK = "268d4e0dd82745f883cac5aec71df3e1";

    public ApiExplorerResponse baiduWeather(WeatherQueryReqDto dto) {
        ApiExplorerRequest request = new ApiExplorerRequest(HttpMethodName.GET, PATH);
        request.setCredentials(AK, SK);
        request.addHeaderParameter("Content-Type", "application/json; charset=utf-8");
        request.addQueryParameter("city", dto.getCity());
        request.addQueryParameter("cityid", dto.getCityId());
        request.addQueryParameter("ip", dto.getIp());
        request.addQueryParameter("province", dto.getProvince());

        ApiExplorerClient client = new ApiExplorerClient(new AppSigner());
        return client.sendRequest(request);
    }
}
